\defmodule{PowerMathFunction}

Represents a function computing $(af(x) + b)^p$ for a user-defined function
$f(x)$ and power $p$.

\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        PowerMathFunction
 * Description:  
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       Éric Buist
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.functions;\begin{hide}

\end{hide}

public class PowerMathFunction implements MathFunction\begin{hide}

,
      MathFunctionWithFirstDerivative {
   private MathFunction func;
   private double a, b;
   private double power;
\end{hide}

   public PowerMathFunction (MathFunction func, double power)\begin{hide} {
      this (func, 1, 0, power);
   }\end{hide}
\end{code}
\begin{tabb}   Constructs a new power function for function \texttt{func} and power
 \texttt{power}. The values of the constants are $a=1$ and $b=0$.
\end{tabb}
\begin{htmlonly}
   \param{func}{the function $f(x)$.}
   \param{power}{the power $p$.}
\end{htmlonly}
\begin{code}

   public PowerMathFunction (MathFunction func, double a, double b, double power)\begin{hide} {
      if (func == null)
         throw new NullPointerException ();
      this.func = func;
      this.a = a;
      this.b = b;
      this.power = power;
   }\end{hide}
\end{code}
\begin{tabb}   Constructs a new power function for function \texttt{func}, power
 \texttt{power}, and constants \texttt{a} and \texttt{b}.
\end{tabb}
\begin{htmlonly}
   \param{func}{the function $f(x)$.}
   \param{power}{the power $p$.}
   \param{a}{the multiplicative constant.}
   \param{b}{the additive constant.}
\end{htmlonly}
\begin{code}

   public MathFunction getFunction ()\begin{hide} {
      return func;
   }\end{hide}
\end{code}
\begin{tabb}   Returns the function $f(x)$.
\end{tabb}
\begin{htmlonly}
   \return{the function.}
\end{htmlonly}
\begin{code}

   public double getA ()\begin{hide} {
      return a;
   }\end{hide}
\end{code}
\begin{tabb}   Returns the value of $a$.
\end{tabb}
\begin{htmlonly}
   \return{the value of $a$.}
\end{htmlonly}
\begin{code}

   public double getB ()\begin{hide} {
      return b;
   }\end{hide}
\end{code}
\begin{tabb}   Returns the value of $b$.
\end{tabb}
\begin{htmlonly}
   \return{the value of $b$.}
\end{htmlonly}
\begin{code}

   public double getPower ()\begin{hide} {
      return power;
   }\end{hide}
\end{code}
\begin{tabb}   Returns the power $p$.
\end{tabb}
\begin{htmlonly}
   \return{the power.}
\end{htmlonly}
\begin{code}\begin{hide}

   public double derivative (double x) {
      final double fder = MathFunctionUtil.derivative (func, x);
      return getA()*getPower()*Math.pow (getA() * func.evaluate (x) + getB(), getPower() - 1)*fder;
   }

   public double evaluate (double x) {
      final double v = func.evaluate (x);
      return Math.pow (a * v + b, power);
   }
}\end{hide}
\end{code}
